package cn.stylefeng.guns.utils.map;

import cn.stylefeng.guns.utils.HttpClientUtil;
import com.alibaba.fastjson.JSON;

/**
 * 百度地图帮助类
 */
public class BaiduMapUtil {
    private static String api = "http://api.map.baidu.com";

    public static String key = "yYUeYesFZxt3G2CQaRBEdRy8eUwDYxnC";

    /**
     * 高德转百度坐标
     * @param location
     * @return
     */
    public static BaiduTransitionResult transition(String location){
        String url = api+"/geoconv/v1/?coords="+location+"&from=3&to=5&ak="+key;
        String result = HttpClientUtil.doGet(url);
        return JSON.parseObject(result,BaiduTransitionResult.class);
    }

    public static BaiduDistanceResult distance(String begLocation,String endLocation) {
        String url = api + "/routematrix/v2/driving?output=json&origins="+begLocation+"&destinations="+endLocation+"&ak="+key+"&tactics=11";
        String result = HttpClientUtil.doGet(url);
        return JSON.parseObject(result, BaiduDistanceResult.class);
    }

    /**
     * 获取城市信息
     * @param location
     * @return
     */
    public static String Geocode(String location){
        String url = api+"/reverse_geocoding/v3/?ak="+key+"&output=json&extensions_poi=1&coordtype=gcj02ll&location="+location+"&radius=1000&extensions=all&batch=false&roadlevel=0";
        String result = HttpClientUtil.doGet(url);
        return result;
    }
}
